<template>
  <div class="shows-container">
    <div class="banner">
      <div class="banner-content">
        <h1>京剧演出</h1>
        <p>探索传统艺术之美，感受国粹魅力</p>
      </div>
    </div>
    
    <div class="introduction-section">
      <div class="intro-content">
        <h2>京剧舞台艺术</h2>
        <p>京剧作为中国国粹，是融合多种地方戏曲而成的一门综合舞台艺术。一场精彩的京剧演出，集唱、念、做、打于一体，通过演员的精湛技艺、华丽的服饰和精巧的舞台设计，将中国传统文化的精髓展现得淋漓尽致。</p>
      </div>
    </div>
    
    <div class="filter-section">
      <div class="search-bar">
        <el-input 
          v-model="searchQuery" 
          placeholder="搜索演出名称" 
          prefix-icon="el-icon-search" 
          clearable
          @keyup.enter.native="handleSearch"
          @clear="handleSearch">
          <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
        </el-input>
      </div>
      
      <div class="filter-options">
        <el-radio-group v-model="showTypeFilter" @change="handleFilterChange">
          <el-radio-button label="">全部</el-radio-button>
          <el-radio-button label="商业">商业</el-radio-button>
          <el-radio-button label="公益">公益</el-radio-button>
          <el-radio-button label="文化交流">文化交流</el-radio-button>
          <el-radio-button label="其他">其他</el-radio-button>
        </el-radio-group>
      </div>
    </div>
    
    <div class="content-section">
      <div class="shows-list" v-loading="loading">
        <div v-for="show in filteredShows" :key="show.showId" class="show-card-container">
          <el-card class="show-card" shadow="hover">
            <div class="show-content">
              <div class="show-poster">
                <img :src="show.posterUrl" alt="演出海报">
                <div class="show-type">
                  <el-tag :type="getTagType(show.showType)">{{ show.showType }}</el-tag>
                </div>
              </div>
              <div class="show-info">
                <h3 class="show-name">{{ show.showName }}</h3>
                <div class="show-details">
                  <p class="show-time"><i class="el-icon-time"></i> {{ formatShowTime(show.showTime) }}</p>
                  <p class="show-address"><i class="el-icon-location"></i> {{ show.showAddress }}</p>
                  <div class="show-description" v-if="show.showDescription">
                    <h4>演出简介：</h4>
                    <p>{{ show.showDescription }}</p>
                  </div>
                </div>
                <div class="show-action">
                  <el-button type="primary" @click="viewShowDetail(show)" round>查看详情</el-button>
                </div>
              </div>
            </div>
          </el-card>
        </div>
        
        <div class="empty-data" v-if="filteredShows.length === 0 && !loading">
          <img src="@/assets/opera_logo.png" alt="暂无数据">
          <p>暂无符合条件的演出</p>
        </div>
      </div>
      
      <div class="pagination-container" v-if="showList.length > 0">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagination.currentPage"
          :page-sizes="[6, 12, 18, 24]"
          :page-size="pagination.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagination.total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import service from '@/utils/request';

export default {
  name: 'ShowsVue',
  data() {
    return {
      showList: [],
      loading: false,
      searchQuery: '',
      showTypeFilter: '',
      pagination: {
        currentPage: 1,
        pageSize: 6,
        total: 0
      }
    };
  },
  computed: {
    filteredShows() {
      if (!this.showTypeFilter) {
        return this.showList;
      }
      return this.showList.filter(show => show.showType === this.showTypeFilter);
    }
  },
  created() {
    this.fetchShowList();
    window.scrollTo(0, 0);
    document.title = '京剧苑 - 京剧演出';
  },
  methods: {
    // 获取演出列表
    fetchShowList() {
      this.loading = true;
      service.get('/api/content/show/getShowList', {
        params: {
          pageNum: this.pagination.currentPage,
          pageSize: this.pagination.pageSize,
          showName: this.searchQuery
        }
      }).then(res => {
        if (res.code === 200) {
          this.showList = res.data.list;
          this.pagination.total = res.data.total;
        } else {
          this.$message.error('获取演出列表失败');
        }
      }).catch(err => {
        this.$message.error(err.message);
      }).finally(() => {
        this.loading = false;
      });
    },
    
    // 格式化显示时间
    formatShowTime(timeString) {
      if (!timeString) return '待定';
      const date = new Date(timeString);
      const year = date.getFullYear();
      const month = date.getMonth() + 1;
      const day = date.getDate();
      const hours = date.getHours();
      const minutes = date.getMinutes();
      
      return `${year}年${month}月${day}日 ${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
    },
    
    // 获取标签类型
    getTagType(showType) {
      const typeMap = {
        '商业': 'success',
        '公益': 'info',
        '文化交流': 'warning',
        '其他': 'primary'
      };
      return typeMap[showType] || 'primary';
    },
    
    // 查看演出详情
    viewShowDetail(show) {
      this.$router.push({
        name: 'ShowDetail',
        params: { id: show.showId }
      });
    },
    
    // 处理搜索
    handleSearch() {
      this.pagination.currentPage = 1;
      this.fetchShowList();
    },
    
    // 处理筛选变化
    handleFilterChange() {
      // 仅在前端筛选，不需要重新请求
    },
    
    // 处理分页大小变化
    handleSizeChange(val) {
      this.pagination.pageSize = val;
      this.fetchShowList();
    },
    
    // 处理当前页变化
    handleCurrentChange(val) {
      this.pagination.currentPage = val;
      this.fetchShowList();
    }
  }
};
</script>

<style scoped>
.shows-container {
  min-height: 100vh;
  padding-bottom: 60px;
  background-color: #f9f5f0;
}

.banner {
  height: 500px;
  background-image: url('../assets/shows/show0.png');
  background-size: cover;
  background-position: center;
  position: relative;
  margin-bottom: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, rgba(139, 0, 0, 0.7), rgba(0, 0, 0, 0.5));
}

.banner-content {
  position: relative;
  z-index: 1;
  text-align: center;
  color: white;
}

.banner-content h1 {
  font-size: 4rem;
  font-family: 'STXingkai', 'STZhongsong', serif;
  margin-bottom: 15px;
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.6);
  color: #FFD700;
  letter-spacing: 10px;
}

.banner-content p {
  font-size: 1.4rem;
  max-width: 600px;
  margin: 0 auto;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  letter-spacing: 3px;
}

.introduction-section {
  padding: 60px 10%;
  background-color: #fff;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  margin-bottom: 40px;
}

.intro-content {
  max-width: 900px;
  margin: 0 auto;
}

.intro-content h2 {
  font-size: 2.4rem;
  color: #8B0000;
  margin-bottom: 30px;
  font-family: 'STZhongsong', serif;
  position: relative;
  display: inline-block;
}

.intro-content h2::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 3px;
  background-color: #8B0000;
}

.intro-content p {
  font-size: 1.2rem;
  line-height: 2;
  color: #333;
  margin-bottom: 20px;
  text-align: justify;
}

.filter-section {
  padding: 20px 5%;
  background-color: #fff;
  margin-bottom: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
}

.search-bar {
  max-width: 500px;
  flex: 1;
  margin: 0 20px 0 0;
}

.filter-options {
  display: flex;
  align-items: center;
}

.content-section {
  padding: 30px 8%;
  max-width: 1200px;
  margin: 0 auto;
}

.shows-list {
  min-height: 300px;
}

.show-card-container {
  margin-bottom: 30px;
}

.show-card {
  transition: all 0.3s ease;
  border: none;
  border-radius: 8px;
  overflow: hidden;
  background-color: rgba(255, 255, 255, 0.95);
}

.show-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 15px 30px rgba(139, 0, 0, 0.15);
}

.show-content {
  display: flex;
  position: relative;
}

.show-poster {
  width: 350px;
  position: relative;
  height: 350px;
  overflow: hidden;
  flex-shrink: 0;
}

.show-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s;
}

.show-card:hover .show-poster img {
  transform: scale(1.05);
}

.show-type {
  position: absolute;
  top: 10px;
  right: 10px;
}

.show-info {
  flex: 1;
  padding: 30px;
  display: flex;
  flex-direction: column;
}

.show-name {
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 1.8rem;
  color: #8B0000;
  font-family: 'STZhongsong', serif;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 15px;
}

.show-details {
  flex: 1;
}

.show-time, .show-address {
  margin: 12px 0;
  color: #555;
  font-size: 1.1rem;
}

.show-description {
  margin-top: 20px;
  color: #666;
}

.show-description h4 {
  font-size: 1.1rem;
  color: #8B0000;
  margin-bottom: 10px;
  font-weight: bold;
}

.show-description p {
  font-size: 1rem;
  line-height: 1.8;
  text-align: justify;
}

.show-time i, .show-address i {
  margin-right: 8px;
  color: #8B0000;
}

.show-action {
  margin-top: 20px;
  text-align: right;
  padding-top: 15px;
  border-top: 1px solid #f0f0f0;
}

.empty-data {
  text-align: center;
  padding: 50px 0;
  color: #999;
  background: #f9f9f9;
  border-radius: 8px;
  margin: 20px 0;
}

.empty-data img {
  width: 150px;
  margin-bottom: 20px;
  opacity: 0.5;
}

.pagination-container {
  text-align: center;
  margin-top: 30px;
  padding: 10px 0;
}

@media (max-width: 1200px) {
  .filter-section {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .search-bar {
    width: 100%;
    margin-bottom: 15px;
    margin-right: 0;
  }
  
  .show-poster {
    width: 240px;
    height: 300px;
  }
}

@media (max-width: 900px) {
  .show-content {
    flex-direction: column;
  }
  
  .show-poster {
    width: 100%;
    height: 250px;
  }
  
  .show-info {
    width: 100%;
    padding: 20px;
  }
}

@media (max-width: 768px) {
  .banner-content h1 {
    font-size: 2.5rem;
    letter-spacing: 5px;
  }
  
  .banner-content p {
    font-size: 1.2rem;
    letter-spacing: 1px;
  }
  
  .banner {
    height: 240px;
  }
  
  .intro-content h2 {
    font-size: 2rem;
  }
  
  .intro-content p {
    font-size: 1rem;
  }
  
  .introduction-section {
    padding: 40px 5%;
  }
  
  .show-name {
    font-size: 1.5rem;
  }
}

@media (max-width: 480px) {
  .banner-content h1 {
    font-size: 2rem;
    letter-spacing: 3px;
  }
  
  .banner-content p {
    font-size: 1rem;
  }
  
  .show-action {
    text-align: center;
  }
  
  .show-time, .show-address {
    font-size: 1rem;
  }
}
</style> 